package com.alex.maze;

import com.alex.maze.entities.Player;
import com.alex.maze.level.Level;
import java.awt.event.KeyEvent;

public class Game
{
    /*  TO-DO ---> Kasnije */
    public int vreme;
    public Level nivo;
    public Player igrac;
    
    public Game()
    {
        //nivo = new Level(32, 32);
        nivo = Level.loadLevel("start");
        igrac = new Player();
        igrac.nivo = nivo; // kolizija
        igrac.x = Level.xSpawn;
        igrac.z = Level.ySpawn;
        nivo.addEntity(igrac); //--->>> OVO OVDE MI JE DODAVALO PLAYER ENTITY NON STOP!!!!!!!! Ali cudno animacija i sa ovim radi... greska mora da je negde drugde... .
        igrac.rot = Math.PI + 0.4; // Sredjivanje kontrola koje cu cak i kasnije da sredjujem... -_- ... Tacnije ovo je spawn rotacija al znas sta mislim.
    }
    
    public void azuriraj(boolean[] keys)
    {
        vreme++;
            
        boolean strafe  = keys[KeyEvent.VK_CONTROL] || keys[KeyEvent.VK_ALT] || keys[KeyEvent.VK_ALT_GRAPH]; // Shift ima da mi bude za trcanje.
        
        boolean upKey = keys[KeyEvent.VK_W] || keys[KeyEvent.VK_UP];
        boolean downKey = keys[KeyEvent.VK_S] || keys[KeyEvent.VK_DOWN];
        boolean leftKey = keys[KeyEvent.VK_A] || (strafe && keys[KeyEvent.VK_LEFT]);
        boolean rightKey = keys[KeyEvent.VK_D] || (strafe && keys[KeyEvent.VK_RIGHT]);
        
        boolean turnleft = keys[KeyEvent.VK_Q] || (!strafe && keys[KeyEvent.VK_LEFT]);
        boolean turnRight = keys[KeyEvent.VK_E] || (!strafe && keys[KeyEvent.VK_RIGHT]);
        
        boolean runKey = keys[KeyEvent.VK_SHIFT]; // Shift za trcanje!
        
        boolean useKey = keys[KeyEvent.VK_SPACE]; //|| keys[KeyEvent.VK_Z]; || keys[KeyEvent.VK_X];
        
        if (useKey)
        {
            keys[KeyEvent.VK_SPACE] = false; 
        } 
        
        igrac.azuriraj(upKey, downKey, leftKey, rightKey, turnleft, turnRight, runKey);
        
        if (useKey)
        {
            igrac.activate();
        }
        
        nivo.update();
    }
}
